package com.service.impl;



import com.alipay.sofa.runtime.api.annotation.SofaService;
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
import com.domain.vo.PriceTypeVo;
import com.domain.vo.ProductStatisticVo;
import com.domain.vo.ProductTop20Vo;
import com.mapper.ReportMapper;
import com.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.time.LocalDate;
import java.util.List;



@Service
@Slf4j
@SofaService(interfaceType = ReportService.class, bindings = { @SofaServiceBinding(bindingType = "bolt") })
public class ReportServiceImpl implements ReportService {


    @Autowired
    private ReportMapper reportMapper;


    /**
     * 查询指定时间端每天兑换量
     * @param startDate
     * @param endDate
     * @return
     */
    @Override
    public List<ProductStatisticVo> getProductStatisticVoByDateRange(LocalDate startDate, LocalDate endDate) {

        Date startSqlDate = Date.valueOf(startDate);
        Date endSqlDate = Date.valueOf(endDate.plusDays(1)); // 设置为下一天的开始时间，确保包含endDate的数据
        return reportMapper.findTotalSalesVolumeByDateRange(startSqlDate, endSqlDate);
    }

    /**
     * 统计指定时间段内，每日兑换方式数量
     * @param startDate
     * @param endDate
     * @return
     */

    @Override
    public List<PriceTypeVo> getPriceTypeByDateRange(LocalDate startDate, LocalDate endDate) {

            // [startDate, endDate)
            // 将 LocalDate表示的日期转换为Date对象，时间部分被设置为00:00:00 GMT。
            Date startSqlDate = Date.valueOf(startDate);
            Date endSqlDate = Date.valueOf(endDate.plusDays(1));
            return reportMapper.getPriceTypeCountByDateRange(startSqlDate, endSqlDate);
    }

    @Override
    public List<ProductTop20Vo> getProductTop20ByDateRange(LocalDate startDate, LocalDate endDate) {
        Date startSqlDate = Date.valueOf(startDate);
        Date endSqlDate = Date.valueOf(endDate.plusDays(1));
        return reportMapper.getProductTop20ByDateRange(startSqlDate, endSqlDate);
    }


}
